<?php
/**
 * Object Relational Persistence Mapping Class for table: msg_favourite_map
 *
 * @package	com.athena
 * @author	LHV
 */
class MsgFavouriteMap extends ORDataObject {

	/**#@+
	 * Fields of table: msg_favourite_map mapped to class members
	 */
	var $msg_favourite_map_id		= '';
	var $user_id		= '';
	var $mapped_user_id		= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'msg_favourite_map';

	/**
	 * Primary Key
	 */
	var $_key = 'msg_favourite_map_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'MsgFavouriteMap';

	/**
	 * Handle instantiation
	 */
	function MsgFavouriteMap() {
		parent::ORDataObject();
	}

	public function addNewMap($userId, $mappedUserId) {
		$data = array (
			'user_id'			=> $userId,
			'mapped_user_id' 	=> $mappedUserId
		);		
		$this->populateArray($data);		
		$this->persist();			
		return $this->msg_favourite_map_id;
	}
	
	public function deleteMap($mappingId) {
		$sql = "DELETE FROM $this->_table WHERE msg_favourite_map_id = $mappingId";
		$res = $this->_execute($sql);
		if ($res === false) {
			return false;
		}
		return true;
	}
	
	public function checkExistingMap($userId, $mappedUserId) {
		$sql = "SELECT msg_favourite_map_id FROM $this->_table
				WHERE user_id = $userId AND mapped_user_id	= $mappedUserId LIMIT 1";
		$res = $this->_execute($sql);
		if (empty($res) || $res->EOF) {
			return false;
		}
		return true;
	}
}
?>
